/**
 * Created by chengming on 18/5/24.
 * version 1.0
 */
const BaseJsonAdapter = require('../base/BaseJsonAdapter');
const request = require('request-promise');
const iconv = require("iconv-lite");
const vm = require('vm');
const cheerio = require('cheerio');
const urlTool = require('url');
const logger = require('../../conf/logger');

/**
 * 中华粮网
 * @type {module.Cngrain}
 */
module.exports = class SjsShangShiGongGao extends BaseJsonAdapter {

	initWinEnv(){
		global.window = {
			innerWidth:1232,
			innerHeight:632,
			screenX:11,
			screenY:22,
			screen:{
				width:1280,
				height:800
			}
		};

		global.document = {
			location:{
				href:''
			},
			documentElement:{
				clientWidth:1217,
				clientHeight:550
			},
			body:{
				clientWidth:1217,
				clientHeight:1467
			},
			_cookie: [],

			get cookie(){
				return this._cookie;
			},

			set cookie(val){
				this._cookie.push(val);
			},

		};


		global.cookie={

		};

	}

	async reqJson(){
		let body =  await this.doRequest();
        let decodeBody = iconv.decode(body, this.encoding).toString();
		console.log(decodeBody)
        vm.runInThisContext(decodeBody);
		let list = [];
		for (var i =0; i<szzbAffiches.length;i++) {
			let item = {};
			let temp = szzbAffiches[i];
			item.title=temp[2];
			item.url=urlTool.resolve(this.pageSite, temp[1]);
			list[i]=item;
		}
		console.log("----------list: " +list)
		return {"list":list};
	}
}